package org.wxy.sdk;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.wxy.sdk.util.JsonStrategy;

import java.lang.reflect.Type;

/**
 * Created by wxy on 2018/05/27.
 *
 * @author wxy
 * @date on 2018/05/27 11:32
 */

public class Constants {
    public static final String APP_LOG_TAG = "Whahol_Tag";
    public static final String API_FILE_SYSTEM_ROOT = "com.czkj.lifehelper.FILE_SYSTEM_ROOT";
    public static final String API_APP_KEY = "com.czkj.lifehelper.APP_KEY";
    public static final String API_APP_SECRET = "com.czkj.lifehelper.APP_SECRET";
    public static final String API_ROOT = "com.czkj.lifehelper.ROOT";
    public static final String API_UUS_ROOT = "com.czkj.lifehelper.UUS_ROOT";
    public static final String API_DEVICE_CONFIG = "com.czkj.lifehelper.DEVICE_CONFIG";
    public static final String API_IM_SERVER = "com.czkj.lifehelper.IM_SERVER";
    public static final String API_URL_ROOT = "com.czkj.lifehelper.URL_ROOT";
    public static final String GRAPHQL_ROOT = "com.czkj.lifehelper.GRAPHQL";
    public static final String LIFE_HELPER_API = "com.czkj.lifehelper.LIFE_HELPER_API";
    public static final java.lang.String COMET_HOST = "com.czkj.lifehelper.COMET_HOST";
    public static final java.lang.String COMET_PORT = "com.czkj.lifehelper.COMET_PORT";

    private static Gson sGsonObject;
    private static JsonStrategy sJsonStrategy;
    private static Gson gson() {
        if (sGsonObject == null) {
            sGsonObject = new GsonBuilder().serializeNulls().disableHtmlEscaping().create();
        }
        return sGsonObject;
    }

    public static JsonStrategy json() {
        if (sJsonStrategy == null) {
            sJsonStrategy = new GsonStrategy();
        }
        return sJsonStrategy;
    }

    private static class GsonStrategy implements JsonStrategy {
        private GsonStrategy(){}
        @Override
        public <T> String toJson(T t) {
            return gson().toJson(t);
        }
        @Override
        public <T> T toJava(String s, Class<T> tClass) {
            return gson().fromJson(s, tClass);
        }

        @Override
        public <T> T toJava(String s, Type type) {
            return gson().fromJson(s, type);
        }
    }

    public static class UserPreference {
        public static final String NAME = "user_preference";
        public static final String USER = "user_user_info";
        public static final String PASSWORD = "user_password";
        public static final String LOGIN_STATE = "user_login_state";
        public static final String FIRST_LOGIN = "user_first_login";
    }
}
